package com.haoxin.ai_course.modules.course.mapper;

import java.util.List;

import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.haoxin.ai_course.modules.course.entity.AcStatisticsAnswer;

/**
 * 题目统计表表
 * 
 * @author xingxiangguo
 * @email bugcn@qq.com
 * @date 2022-06-06 09:44:49
 */
public interface AcStatisticsAnswerMapper  extends BaseMapper<AcStatisticsAnswer> {
	@Select("SELECT "
			+ " course_id courseId,"
			+ "	topic_id topicId,"
			+ "	answer_id answerId,"
			+ "	topic_code topicCode,"
			+ "	answer_code answerCode,"
			+ "	topic_content topicContent,"
			+ "	answer_content answerContent,"
			+ "	ifnull( count( 1 ), 0 ) selectedCount,"
			+ "	ifnull("
			+ "		ifnull( count( 1 ), 0 )/("
			+ "		SELECT"
			+ "			count( 1 ) "
			+ "		FROM"
			+ "			ac_topic_answer_result "
			+ "			"
			+ "			a where a.topic_id = b.topic_id"
			+ "		)* 100,"
			+ "		0.0 "
			+ "	) selectedRate "
			+ " FROM"
			+ "	ac_topic_answer_result b"
			+ " where course_id=#{courseId}"
			+ " and topic_id=#{topicId}"
			+ " GROUP BY"
			+ "	answer_id ")
	List<AcStatisticsAnswer> countSelectRateAndSelectedCount(@Param("courseId")  Integer courseId,@Param("topicId") Integer topicId);
	
}
